#!/bin/bash

cd /opt/guard

# check pid.txt file is exists
if [ -f pid.txt ]; then
    PID=$(cat pid.txt)
    # check PID is exists and is number
    if [ ! -z "$PID" ]; then
            echo "stopping guard，PID: $PID"
            kill $PID
            # 检查进程是否成功停止
            if [ $? -eq 0 ]; then
                    echo "guard successfully stopped"
                    > pid.txt
            else
                    echo "can't stop guard"
            fi
    else
            echo "guard program is not start or stopped"
    fi
else
        echo "guard program is not start"
fi